using System;
using System.Configuration;
using System.Windows.Forms;

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Security;
using DevExpress.ExpressApp.Win;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;
using DevExpress.ExpressApp.Workflow.Win;
using DevExpress.ExpressApp.Workflow;
using DevExpress.ExpressApp.Utils;
using Top.Module.Activities;

namespace Ascent.Win
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            //DevExpress.Data.CurrencyDataController.DisableThreadingProblemsDetection = true;
#if EASYTEST
			DevExpress.ExpressApp.EasyTest.WinAdapter.RemotingRegistration.Register(4100);
#endif

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            EditModelPermission.AlwaysGranted = System.Diagnostics.Debugger.IsAttached;
            AscentWindowsFormsApplication winApplication = new AscentWindowsFormsApplication();

            winApplication.Modules.FindModule<WorkflowWindowsFormsModule>().QueryAvailableActivities +=
            delegate(object sender, ActivitiesInformationEventArgs e)
            {
                e.ActivitiesInformation.Add(new ActivityInformation(typeof(TopActivity<>), "Top Activities", "TopActivity", ImageLoader.Instance.GetImageInfo("TopActivity").Image));
            };

#if EASYTEST
			if(ConfigurationManager.ConnectionStrings["EasyTestConnectionString"] != null) {
				winApplication.ConnectionString = ConfigurationManager.ConnectionStrings["EasyTestConnectionString"].ConnectionString;
			}
#endif
            if (ConfigurationManager.ConnectionStrings["ConnectionString"] != null)
            {
                winApplication.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
            }
            try
            {
                winApplication.Setup();
                winApplication.Start();
            }
            catch (Exception e)
            {
                winApplication.HandleException(e);
            }
        }
    }
}
